package cn.thoughtworks.school.response;

import cn.thoughtworks.school.entities.Video;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.util.Date;
import java.util.Map;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SimpleVideoResponse {
  private Long id;
  private String coverUrl;
  private String url;
  private String title;
  private Boolean isPublic;
  private String username;
  @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
  private Date createTime;

  public static SimpleVideoResponse build(Map user, Video video) {
    return SimpleVideoResponse.builder()
      .id(video.getId())
      .coverUrl(video.getCoverUrl())
      .url(video.getUrl())
      .title(video.getTitle())
      .isPublic(video.getIsPublic())
      .createTime(video.getCreateTime())
      .username(user.get("name").toString()).build();
  }
}
